package com.wf.demo.info.web;

import com.wf.demo.info.dao.ParseDAO;
import com.wf.demo.info.pojo.Device;
import com.wf.demo.info.pojo.Match;
import com.wf.demo.info.pojo.Parse;
import com.wf.demo.info.service.MatchService;
import com.wf.demo.info.service.ParseService;
import com.wf.demo.info.util.Page4Navigator;
import com.wf.demo.info.util.Result;
import com.wf.demo.sys.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: wf
 * @Date: 2019/11/23 22:11
 * @Description:
 */
@RestController
public class MatchController {
    @Autowired
    MatchService matchService;
    @Autowired
    ParseDAO parseDAO;
    //parse下所有match
    @GetMapping("/parses/{pid}/matchs")
    @RequiresPermissions("info:match")
    public List<Match> list(@PathVariable("pid")int pid){
        return matchService.list(pid);
    }
    @GetMapping("/matchs/{id}")
    public Object get(@PathVariable("id")int id){
        Match bean= matchService.get(id);
        return bean;
    }
    @SysLog("保存匹配信息")
    @PostMapping("/matchs")
    @RequiresPermissions("info:match")
    public Object add(@RequestBody Match bean) throws Exception{

        boolean exit=matchService.isExist(bean.getDataValue(),bean.getParse());
        if(exit){
            String message="此数值已存在，添加失败";
            return Result.addFail(message);
        }
        matchService.add(bean);
        return Result.addSuccess(bean);
    }

    @SysLog("删除匹配信息")
    @DeleteMapping("/matchs/{id}")
    @RequiresPermissions("info:match")
    public String delete(@PathVariable("id")int id){
        matchService.delete(id);
        return null;
    }
    @SysLog("修改匹配信息")
    @PutMapping("/matchs")
    @RequiresPermissions("info:match")
    public Object update(@RequestBody Match bean) throws Exception{
        boolean exit=matchService.isExist(bean);
        if(exit){
            String message="此数值已存在，添加失败";
            return Result.addFail(message);
        }
        matchService.update(bean);
        return Result.addSuccess(bean);
    }
}
